﻿using Newtonsoft.Json;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;

namespace muyu_monitor_plugin
{
    public static class ConfigManager
    {
        private static readonly string FilePath = "config.json";

        public static void SaveConfig(ConfigData configData)
        {
            string json = JsonConvert.SerializeObject(configData);
            File.WriteAllText(FilePath, json);
        }

        public static ConfigData LoadConfig()
        {
            if (File.Exists(FilePath))
            {
                string json = File.ReadAllText(FilePath);
                return JsonConvert.DeserializeObject<ConfigData>(json);
            }

            return new ConfigData();
        }
    }

    public class ConfigData
    {
        public string ProductKey { get; set; }
        public string DeviceName { get; set; }
        public string Secret { get; set; }
        public ObservableCollection<MessageConfigItem> MessageConfigItems { get; set; }

        public ConfigData()
        {
            MessageConfigItems = new ObservableCollection<MessageConfigItem>();
        }
    }
}
